/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Business;

import DAO.Customer_DAO;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Storm^^Rain
 */
public class Customer_MD extends AbstractTableModel {

    private List<Customer_BS> customers;
    private final String columnsName[] = {"Code", "Name", "Type", "Phone", "Address"};
    private final Class columnsClass[] = {String.class, String.class, String.class, String.class, String.class};
    
//    Customer_DAO dao = new Customer_DAO();
//
//    public List<Customer_BS> getCustomers() {
//        return dao.getCustomers();
//    }

    
    public Customer_MD(List<Customer_BS> customers) {
        this.customers = customers;
    }
    
    public int getRowCount() {
        return customers.toArray().length;
    }

    public int getColumnCount() {
        return columnsName.length;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return customers.get(rowIndex).getcID();
            
            case 1:
                return customers.get(rowIndex).getCName();
            
            case 2:
                switch(customers.get(rowIndex).getCType()) {
                    case 0: 
                        return "General Customer";
                        
                    case 1:
                        return "Dealer";
                        
                    case 2:
                        return "Who sale Retailer";
                                               
                    default:
                        return "";
                }
                
            case 3:
                return customers.get(rowIndex).getCPhone();
                
            case 4:
                return customers.get(rowIndex).getCAddress();
                
            default:
                return null;
                                  
        }
    }
    
    @Override
    public String getColumnName(int iCol) {
        return columnsName[iCol];        
    }

    @Override
    public Class getColumnClass(int iCol) {
        return columnsClass[iCol];
    }

//    private void getAllCustomer() {
//        DAO.Customer_DAO.getAllCustomer();
//        fireTableDataChanged();
//    }

    public Customer_BS getCustomer(int rowIndex) {
        fireTableDataChanged();
        return customers.get(rowIndex);
    }
    public void createCustomer(Customer_BS customer){
        fireTableDataChanged();
    }

    public void updateCustomer(Customer_BS customer) {
        fireTableDataChanged();
    }

    public void deleteCustomer(Customer_BS customer) {
        customers.remove(customer);
        fireTableDataChanged();
    }
}
